package com.tsunami.authority.enums.auth;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author lx
 */
@Getter
@NoArgsConstructor
@Schema(description = "授权类型-枚举")
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum GrantType {
    /**
     * 授权码模式
     */
    AUTHORIZATION_CODE("authorization_code", "授权码模式"),
    /**
     * 密码模式
     */
    PASSWORD("password", "密码模式"),
    /**
     * 客户端模式
     */
    CLIENT_CREDENTIALS("client_credentials", "客户端模式"),
    /**
     * 简化模式
     */
    IMPLICIT("implicit", "简化模式"),
    /**
     * 刷新token
     */
    REFRESH_TOKEN("refresh_token", "刷新");
    private String code;
    private String info;

    GrantType(String code, String info) {
        this.code = code;
        this.info = info;
    }

    public String getCode() {
        return code;
    }

    public String getInfo() {
        return info;
    }

    public static GrantType getEnum(String code) {
        for (final GrantType item : GrantType.values()) {
            if (item.code.equals(code)) {
                return item;
            }
        }
        return null;
    }
}
